package comm;

import game.*;
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.*;

public class CommMidlet extends MIDlet implements CommandListener {

    Display display;
    static final Command comandoVoltar = new Command("Voltar", Command.EXIT, 0);
    static final Command comandoOK = new Command("OK", Command.OK, 0);
    Form initialForm = new Form("Multiplayer");
    ChoiceGroup choice = new ChoiceGroup("Modo", Choice.EXCLUSIVE);

    public void startApp() {

        display = Display.getDisplay(this);
        initialForm.addCommand(comandoVoltar);
        initialForm.addCommand(comandoOK);        
        initialForm.setCommandListener(this);
        
        choice.append("Servidor", null);
        choice.append("Cliente", null);
        
        initialForm.append(choice);
        
        display.setCurrent(initialForm);
        //canvas.start();

    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {

        notifyDestroyed();
    }

    public void commandAction(Command c, Displayable d) {
        if (c.getCommandType() == Command.EXIT && c == comandoVoltar) {
            //canvas.stop();
            destroyApp(true);
        }
        else if(c.getCommandType() == Command.OK && c == comandoOK)
        {
            System.out.println("Selecionado: " + choice.getSelectedIndex());
            
            ClientServer clientServer;
            
            if(choice.getSelectedIndex() ==0)
            {
                clientServer = new ClientServer(true);
            }
            else
            {
                clientServer = new ClientServer(false);
            }
            
            
        }
    
    }
}
